//1.
const fp = require ('lodash/fp');
const {Maybe, Container} = require('./support');

let maybe = Maybe.of([5,6,1]);
let ex1 = (functor) => {
    return functor.map(x=>fp.map(v=>fp.add(v,1),x))//just add 1 for each value
}

console.log('ex1:\n',ex1(maybe));

//2.
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])

let ex2 = (functor) => {
    return functor.map(v=>fp.first(v));
}

console.log('ex2:\n', ex2(xs))

//3.
let safeProp = fp.curry(function(x,o){
    return Maybe.of(o[x]);
})
let user = { id: 2, name: 'Albert'};
let ex3 = (obj)=>{
    return safeProp('name',obj).map(x=>fp.first(x));
}
console.log('ex3:\n',ex3(user))

//4.
//    let ex4 = function (n){
//        if(n){
//            return parseInt(n);
//        }
//    }

let ex4 = (n) => Maybe.of(n).map(x => parseInt(x))
console.log('ex4:\n', ex4('1'))
console.log(ex4(null))
